package com.lzy.liujing.restaurant.controller.sysController;

import com.lzy.liujing.restaurant.entity.Result;
import com.lzy.liujing.restaurant.entity.SysUser;
import com.lzy.liujing.restaurant.service.SysUserService;
import com.lzy.liujing.restaurant.utils.ResultUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.util.List;

/**
 * Created with IDEA
 * author:LiuJing
 * Date:2018/10/2
 * Time:15:20
 *
 * 登录模块接口
 */

@RestController
@CrossOrigin
@RequestMapping("/sysuser")
public class LoginController{
   @Autowired
   private SysUserService sysUserService;
    /**登录功能
     *  @Valid 表示验证该对象   验证结果保存到BindingResult对象中
     */
    @PostMapping("/login")
    public Result login(@RequestBody SysUser acc){
        Result result = new Result();
        SysUser login = sysUserService.login(acc);
        if(login == null){
            result.setMsg("Login failed");
            result.setCode(500);
        }
        result.setMsg("Login success");
        result.setCode(200);
        result.setData(login);
        return result;
    }

}
